import 'package:boss/models/staff.dart';
import 'package:boss/provider/staff_provider.dart';
import 'package:boss/ui/page/role/provider/role_provider.dart';
import 'package:boss/ui/widget/alert/alert.dart';
import 'package:boss/ui/widget/back_confirmation.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'provider/staff_detail_provider.dart';
import 'widget/staff_detail_browser.dart';

@RouterConfig(StaffDetailPage.pageName)
class StaffDetailPage extends StatefulWidget {
  static const pageName = '/staffDetailPage';

  @Autowired()
  final Staff staff;

  const StaffDetailPage({
    Key key,
    this.staff,
  }) : super(key: key);

  @override
  _StaffDetailPageState createState() => _StaffDetailPageState('员工详情');
}

class _StaffDetailPageState extends BaseState<StaffDetailPage> {
  _StaffDetailPageState(String pageName) : super(pageName);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => StaffDetailProvider(staff: widget.staff),
      child: BackConfirmation(
        backConfirmationText: '员工信息还未完成确认返回么？',
        child: Scaffold(
          appBar: CenterTitleAppBar(
            title: '编辑员工信息',
            backConfirmationText: '员工信息还未完成确认返回么？',
            actions: <Widget>[
              LabelButton(
                title: '删除',
                padding: EdgeInsets.only(left: 8, top: 2, bottom: 2),
                onTap: () async {
                  Provider.of<StaffProvider>(context, listen: false).deleteStaff(widget.staff);
                },
              ),
            ],
          ),
          body: StaffDetailBrowser(),
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();

    Provider.of<RoleProvider>(context, listen: false).initData();
  }
}
